package util;

import java.io.PrintWriter;
import java.sql.*;

import javax.servlet.ServletException;
import javax.management.*;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class User {
    private boolean ok = false;//状态变量
    private String name = null;
    private String pass = null;



    public boolean check() throws Exception {
        checkSQL(this.name, this.pass);
        return this.ok;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public String getPass() {
        return pass;
    }

    //查询数据库，如果数据库没有这个用户就把状态变量设置为false，如果有则设置为true
    private void checkSQL(String name, String pass) throws Exception {

        DButil dButil = new DButil();

        Connection con = dButil.getConnection();

        Statement st = con.createStatement();

        ResultSet rs = st.executeQuery("select * from user where username='" + name + "' and password='" + pass + "'");

        if (rs.next()) {//表示有记录
            this.ok = true;
        } else {
            this.ok = false;
        }
    }
}